<template>
  <div class="homework-layout">
    <div class="layout-container">
      <!-- 公共侧边栏 -->
      <div class="sidebar">
        <div class="sidebar-header">
          <h3>习题管理</h3>
        </div>
        <el-menu
          :default-active="activeMenu"
          class="sidebar-menu"
          @select="handleMenuSelect"
        >
          <el-menu-item index="generator">
            <el-icon><Edit /></el-icon>
            <span>习题定制</span>
          </el-menu-item>
          <el-menu-item index="history">
            <el-icon><List /></el-icon>
            <span>历史记录</span>
          </el-menu-item>
        </el-menu>
      </div>

      <!-- 主内容区 -->
      <div class="main-content">
        <router-view></router-view>
      </div>
    </div>
  </div>
</template>

<script setup>
import { ref, computed } from 'vue'
import { useRouter, useRoute } from 'vue-router'
import { Edit, List } from '@element-plus/icons-vue'

const router = useRouter()
const route = useRoute()

// 根据当前路由计算激活的菜单项
const activeMenu = computed(() => {
  const path = route.path
  if (path.includes('/generator')) return 'generator'
  if (path.includes('/history')) return 'history'
  return 'generator'
})

// 处理菜单选择
const handleMenuSelect = (index) => {
  switch (index) {
    case 'generator':
      router.push('/homework/generator')
      break
    case 'history':
      router.push('/homework/history')
      break
    default:
      break
  }
}
</script>

<style scoped>
/* .homework-layout {
  padding: 20px;
  max-width: 1600px;
  margin: 0 auto;
  margin-top: 60px;
  min-height: calc(100vh - 100px);
} */
.homework-layout {
  padding: 20px;
  height: 100vh;
  box-sizing: border-box;
}

.layout-container {
  display: flex;
  /* gap: 20px; */
  height: 100%;
}

.sidebar {
  width: 240px;
  background-color: #fff;
  border-radius: 8px;
  box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.1);
  position: sticky;
  top: 80px;
  height: calc(100vh - 100px);
  overflow-y: auto;

  flex-shrink: 0;
}

.sidebar-header {
  padding: 15px 20px;
  border-bottom: 1px solid #ebeef5;
}

.sidebar-header h3 {
  margin: 0;
  font-size: 16px;
  color: #303133;
  font-weight: 600;
}

.sidebar-menu {
  border-right: none;
}

.main-content {
  flex: 1;
  min-width: 0;
  background-color: #fff;
  border-radius: 8px;
  box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.1);
  padding: 20px;
  min-height: calc(100vh - 100px);

  overflow: auto;
}
</style>
